using System.Collections.Generic;
using LitJson;
namespace CGF
{
    public partial class PanelLeaseRecoards : UIComponentBase, IAwake<UILayer, bool>, IDestroy
    {
        public static void Open()
        {
            UIManagerComponent.instance.OpenUI<PanelLeaseRecoards>(UILayer.Normal, RootComponent.instance, false);
        }

        public static void Close()
        {
            UIManagerComponent.instance.CloseUI<PanelLeaseRecoards>();
        }

        public async void Awake(UILayer layer, bool isFloat)
        {
            await SpawnPrefab("Prefabs/GameUI/PanelLeaseRecoards", layer, isFloat);
            BindProperties(transform);

            BtnBack.SetClick(Close);

            //表
            string api = "/v1/order";
            string listKey = "orders";
            string[] type = { "EXP", "PRO", "ULT" };
            Table.Column[] columns =
            {
                (cell, data) => TimeHelper.Parse2Date(data["created_at"].ToString(), false),
                (cell, data) =>
                {
                    JsonData shopData = GlobalData.GetDeviceByShopId((int)data["shop_id"]);
                    return $"{type[(int)shopData["type"] - 1]}({I18N_days.Replace("{num}", shopData["period"].ToString())})";
                },
                (cell, data) => (int)data["type"] == 0 ? I18N_buy : I18N_renew,
                (cell, data) => $"<color={Config.NumColor}>{I18N.Currency}<b>{StringHelper.Format2Decimal((int)data["amount"] * 0.01f)}</b></color>",
            };
            Table.GetComponent<Table>().ReqData(api, listKey, columns);
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
        }

    }
}
